package com.cw.controller;


import com.cw.annotation.*;
import com.cw.common.constant.*;
import com.cw.entity.*;
import com.cw.service.*;
import com.cw.websocketlocal.WebSocket;
import io.swagger.annotations.*;

import java.io.IOException;
import java.util.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RestController;

/**
* @author smq
* @since 2021-04-27
*/
@Api(tags = {"病区"})
@RestController
@RequestMapping("/area")

    public class AreaController {

    @Autowired
    private IAreaService targetService;

    @Autowired
    WebSocket webSocket;

    @PostMapping("/saveOrUpdate")
    @ApiOperation("新建或编辑")
    @ResultObjectAnnotation(value=DmlTypeConstant.INSERT,successMessage = "新建或编辑成功!",errorMessage = "新建或编辑失败!")
    public Object saveOrUpdate(@RequestBody Area Area) {
    return targetService.saveOrUpdate( Area);
    }


    @GetMapping("/getById/{id}")
    @ApiOperation("查看")
    @ResultObjectAnnotation(DmlTypeConstant.SELECT)
    public Object getById(@PathVariable String id) {
    return targetService.getById(id);
    }


    @DeleteMapping("/delete/{ids}")
    @ApiOperation("删除")
    @ResultObjectAnnotation(DmlTypeConstant.DELETE)
    public Object delete(@PathVariable List
    <String> ids) {
      return targetService.removeByIds(ids);
      }

    @ApiOperation("sendTo")
    @ResponseBody
    @GetMapping("/sendTo")
    public String sendTo(@RequestParam("userId") String userId,@RequestParam("msg") String msg) throws IOException {

        webSocket.sendMessageTo(msg,userId);

        return "推送成功";
    }

}

